#include<iostream>
#include<vector>

using namespace std;

class Test{

public:
    int i;
    int n;
    int m;

    Test(int i_ = 1)  {
        i = 1;
        n = i_;
        m = 0;
        cout << "Test()" << i << " addr:" << static_cast<void*>(this) << endl;
    }

    Test(const Test& t) {
        i = 3;
        n = t.i;
         m = 1;
        cout << "Test(const Test& t)" << i << " addr:" << static_cast<void*>(this)  << " obj addr:" << (void*)(&t) << endl;
    }

    Test(Test&& t){
        i = 4;
        m = 4;
        t.m = 0;
        cout << "Test(const Test&& t)" << i << " addr:" << static_cast<void*>(this)  << " obj addr:" << (void*)(&t) << endl;
    }

    ~Test() {
         cout << "~Test()" << i <<  " addr:" << static_cast<void*>(this) << endl;
    }

    void fun() {
        cout << "func"<< " addr:" << static_cast<void*>(this) << endl;
    }

    
};

Test creatTest() {
    
    return Test(4);
}

Test creatRef() {
    return creatTest();
}

Test& ret() {
    Test t;

    return t;
}


std::vector<int> creatVct() {
    std::vector<int> vct{1, 2, 3, 4};
    cout << static_cast<void*>(&vct) << endl;
    return vct;
}

int main()
{
    // auto& pt = ret();
    // pt.fun();

    // int i;
    // int& ii = i;
    // int& iii = ii;

    auto  n =  creatTest();

    cout << "m:" << n.m << endl;

    auto nn = std::move(n);
    cout << "nn.m:" << nn.m << endl;
    cout << "n.m:" << n.m << endl;
    
    // auto&& v = creatVct();
    // cout << static_cast<void*>(&v) << endl;

  //  auto test = creatTest();
    // auto test = creatRef();

    // test.fun();
    return 0;
}

// 一般：
// 编译器会默认打开函数返回值的优化  named return value optimizatio

// 编译时 添加参数 -fno-elide-constructors  可强制按照原有的语义去构造

// -fno-elide-constructors result:  
/*
Test()1
Test(const Test& t)3
~Test()1
~Test()3

*/

// result
/*
Test()1
~Test()1
*/